package org.liuyunfeng.web;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CyclicBarrier;

/**
 * @description:
 * @author: TanJingyu
 * @create: 2023-02-09 14:28
 **/
@RestController
@RequestMapping("/aqs")
public class AQSController {
    private final CountDownLatch countDownLatch = new CountDownLatch(5);
    private final CyclicBarrier cyclicBarrier = new CyclicBarrier(2);


    @GetMapping("/countDownLatch")
    public String countDownLatch() throws InterruptedException {
        countDownLatch.await();
        return "放行了";
    }

    @GetMapping("/countDownLatch/countDown")
    public String countDownLatchDown() {
        countDownLatch.countDown();
        return "还剩多少： " + countDownLatch.getCount();
    }

    @GetMapping("/cyclicBarrier")
    public String cyclicBarrier() throws BrokenBarrierException, InterruptedException {
        cyclicBarrier.await();
        return "cyclicBarrier完成了！";
    }
}

    